<?php
namespace Wap\Controller;
use Wap\Controller\CommonController;
class CommentController extends CommonController {

    /**
      +----------------------------------------------------------
     * 首页
     *
      +----------------------------------------------------------
     */
    public function ask() {
    	$M=new \Think\Model('ask');
      if(isset($_GET['cmt'])){	
        $arr=json_decode($_GET['cmt'],true);
        $data['nickname']=htmlspecialchars(strip_tags($arr['username']));
        $data['content']=htmlspecialchars(strip_tags($arr['content']));
        $data['addtime']=time();
        if($M->add($data)){
        	echo json_encode(array('error'=>0,'message'=>'已提交您的疑问!请您刷新查看！'));
        }else{
        	echo json_encode(array('error'=>1,'message'=>'提交失败！！'));
        }
      }else{
      	$list= $M->where('status=1')->order('id desc')->select();
      	echo $_GET['callback'].'('.json_encode($list).')';
      }
    }
    
    
    public function  comment(){
    	$M=new \Think\Model('comment');
    	if(isset($_GET['cmt'])){
    		$arr=json_decode($_GET['cmt'],true);
    		$data['nickname']=htmlspecialchars(strip_tags($arr['username']));
    		$data['content']=htmlspecialchars(strip_tags($arr['content']));
    		$data['addtime']=time();
    		if($M->add($data)){
    			echo json_encode(array('error'=>0,'message'=>'已提交您的评论!请您刷新查看'));
    		}else{
    			echo json_encode(array('error'=>1,'message'=>'提交失败！！'));
    		}
    	}else{
    		$list= $M->where('status=1')->order('id desc')->select();
    		foreach($list as &$v){
    			$v['addtime']=date("Y-m-d H:i:s",$v['addtime']);
    		}
    		echo $_GET['callback'].'('.json_encode($list).')';
    	}
    }

}

?>